<?php

namespace App\Http\Controllers\api\login;

use App\Http\Controllers\Controller;
use App\Logic\apiLogin\login;
use App\Server\ApiService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;

class LoginController extends Controller
{
    /**
     * fw
     * 发送短信服务
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    function sendSms(Request $request){
        $phone=$request->input('phone');
        Cache::put('phone'.$phone,$phone);
        $res=login::sendSms($phone);

        return ApiService::success('发送短信成功，请查收',$res);
    }
    /**
     * fw
     * 小程序短信登陆
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    function login(Request $request){
        $code=$request->input('code');
        $phone=$request->input('phone');

        $token=login::check($code,$phone);
        return ApiService::success('登陆成功',$token);
    }
    /**
     * fw
     * 微信授权登陆
     * @param Request $request
     */
    function wxLogin(Request $request){
        $nickName=$request->input('nickName');
        
        $code=$request->input('code');
        $token=login::empower($nickName,$code);
        return ApiService::success('微信授权登陆成功',$token);
    }
}
